# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  before_filter :authorize, :except => :login
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
  
  def admin_required
    current_user = User.find_by_id(session[:user_id])
    unless current_user.is_Administrator?
      flash[:notice] = "Sorry, administrator privileges required."
	  redirect_to :controller => 'user_main', :action => 'index'
    end
  end
  
protected
    def authorize
	  unless User.find_by_id(session[:user_id])
	    flash[:notice] = "Please log in"
	    redirect_to :controller => 'home', :action => 'index'
	  end
    end
end
